import type { WhiteNameList } from './constant';
import { isNavigationFailure, NavigationFailureType, type Router } from 'vue-router';
import NProgress from 'nprogress';

NProgress.configure({ showSpinner: true });

export function createRouterGuards(router: Router, whiteNameList: WhiteNameList) {
  // const useStore = useUserStore(); // 获取用户信息
  console.log(whiteNameList);

  // 全局前置守卫
  router.beforeEach((to, from, next) => {
    // console.log(to);

    // 判断当前路由是否需要隐藏进度条
    // if (!from.meta?.hideProgress || !to.meta?.hideProgress)
    NProgress.start();

    // console.log('全局前置守卫')

    // if (userStore.token) {

    // } else {

    // }

    next();
  });

  // 全局后置守卫
  router.afterEach((to, from, failure) => {
    // console.log('全局后置守卫')
    if (isNavigationFailure(failure, NavigationFailureType.aborted)) {
      NProgress.done();
    }

    if (to.meta?.title) {
      document.title = to.meta.title as string;
    }

    // const keepAliveStore = useKeepAliveStore();

    // const toCompName = getComponentName(to);

    NProgress.done();
  });

  // 全局解析守卫
}
